/**
 * 极速问诊数据
 */
import type { IllnessType, PartialConsult } from "@/types/consult";
import { ConsultType } from "@/types/enum";
import { defineStore } from "pinia";
import { ref } from "vue";
export const useConsultStore = defineStore('cp-consult',()=>{
    // 定义全局共享数据
    /**
     * 1问诊记录数据，创建订单使用全局变量
     * =================================
     * 修改全局变量的方法
     * 1. 修改问诊类型方法1.找医生，2.快速问诊，3.开药问诊
     * 2.修改极速问诊级别方法0。普通问诊，1.三甲医院
     * 3. 修改科室方法
     * 4. 修改病情描述信息
     * 5.修改患者
     * 6.修改优惠卷
     * 7.清空问诊记录
     */
    const consult = ref<PartialConsult>({})
    // 首页使用：记录问诊类型
    const setType = (type:ConsultType)=>{
        consult.value.type = type
    }
    // 问诊级别:记录问诊级别
    const setIllnessType = (type:0|1)=>{
        consult.value.illnessType = type
    }
    // 3.选择科室页面:记录科室
    const setDepId = (id:string) => {
        consult.value.depId = id
    }
    // 4.病情描述页面:记录病情描述
    const setIillness = (illness:Pick<IllnessType,'illnessDesc'|'illnessTime'|'consultFlag'|'pictures'>) => {
        consult.value.illnessDesc = illness.illnessDesc
        consult.value.illnessTime = illness.illnessTime
        consult.value.pictures = illness.pictures
        consult.value.consultFlag = illness.consultFlag
    }
    // 5.家庭档案页面:记录患者id
    const setPatientId = (id:string) => {
        consult.value.patientId = id
    }
    // 6. 优惠券页面:记录优惠券id
    const setCunpon = (id:string) => {
        consult.value.couponId = id
    }
    // 7.清空问诊记录
    const clear = () =>{
        consult.value = {}
    }
    
    return {
        consult,
        setType,
        setIllnessType,
        setDepId,
        setIillness,
        setPatientId,
        setCunpon,
        clear
    }
},{
    persist: true
  })